<?php defined('SYSPATH') or die('No direct script access.');

abstract class Controller_Index_Base extends Controller
{
    protected $_title  = 'OptZilla';
	protected $_layout = 'index/layout_tpl';
    
    public function before()
    {
        parent::before();
        
        $this->_get_params();   
    }
    
    protected function _get_params()
    {
        $changed = false;
        $url     = $_SERVER['REQUEST_URI'];
        if (isset($_GET['subid']) && ($subid = $_GET['subid'])) {
            //$this->_redirect_if_neccesary($subid);
            setcookie('subid', $subid, time()+30*24*60*60, '/');     // 30 дней 
            
            $url = str_replace(array('?subid='.$subid, '&subid='.$subid), array('', ''), $url); 
            $changed = true;
        }
        /*if (isset($_GET['utm_source']) && $_GET['utm_source'] == 'recommend' &&
            isset($_GET['utm_medium']) && $_GET['utm_medium'] == 'referral' &&
            isset($_GET['utm_campaign']) && ($recommend = $_GET['utm_campaign'])) {
            setcookie('recommend', $recommend, time()+3*30*24*60*60, '/');     // 90 дней 
        }    */
        /*if (isset($_GET['cat']) && ($cat = $_GET['cat'])) {
            $session = Session::instance();
            $session->set('category-redirect', $cat);
            
            $url = str_replace(array('?cat='.$cat, '&cat='.$cat), array('', ''), $url);
            $changed = true;
        }  */
        
        if ($changed) {
            Helper_Index::redirect_301($url);    
        }
    }
	
	public function print_template($title, $content)
	{
        $this->_layout = new View($this->_layout);

		$this->_layout->title       = $title.' - '.$this->_title;
		$this->_layout->content     = $content;
		
		$this->response->body($this->_layout);
	}

}
